package cn.z2huo.knowledge.basic.recordclass;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *
 * @author z2huo
 */
class RecordNoRepeatTest {

    public static void main(String[] args) {

        List<UserDO> userDOS = List.of(
                new UserDO().setUserCode("18182026").setUserName("张三").setOrgCode("1300"),
                new UserDO().setUserCode("18182026").setUserName("张三").setOrgCode("1100"),
                new UserDO().setUserCode("71403112").setUserName("王五").setOrgCode("1300")
        );

        // 将用户列表根据用户代码去重
        List<UserDO> list = userDOS.stream().distinct().toList();
        System.out.println(list);

        record User(String userCode, UserDO userDO) {
            @Override
            public boolean equals(Object o) {
                if (o == null || getClass() != o.getClass()) return false;
                User user = (User) o;
                return Objects.equals(userCode, user.userCode);
            }
            @Override
            public int hashCode() {
                return Objects.hashCode(userCode);
            }
        }

        List<UserDO> list1 = userDOS.stream().map(userDO -> new User(userDO.getUserCode(), userDO))
                .distinct().map(User::userDO).toList();
        System.out.println(list1);
    }

}
